package com.example.kotlindemo.base

import android.app.FragmentManager
import android.app.FragmentTransaction
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.kotlindemo.R
import com.example.kotlindemo.title_utils.StatusBarUtil
import java.util.*

/**
 * @功能:
 * @Creat 2019/07/11 10:33
 * @User Lmy
 * @By Android Studio
 */
abstract class BaseActivity : AppCompatActivity() {
    private val manager: FragmentManager? = null
    private val transaction: FragmentTransaction? = null
    protected var context: Context? = null
    //加载类型是否是上拉加载
    protected var isPullonloading = false
    //分页的页码
    protected var page = 1
    protected var parms: Map<String, String>? = null
    protected var linearLayoutManager = LinearLayoutManager(this)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ActivityManager.getInstance().pushOneActivity(this)
        context = applicationContext
        parms = HashMap()
        /**
         * 禁止封装的headtitle头布局自动弹出输入键盘
         * 如需进入Activity自动弹出则在相应的Activity
         * 设置getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
         */
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
        StatusBarUtil.setRootViewFitsSystemWindows(this, true)
        /**
         * 设置状态栏透明StatusBarUtil.setTranslucentStatus(this);
         */
        StatusBarUtil.setStatusBarColor(this, resources.getColor(R.color.white))
        if (!StatusBarUtil.setStatusBarDarkTheme(this, true)) {
            /**
             * 如果不支持设置深色风格 为了兼容总不能让状态栏白白的看不清
             * 于是设置一个状态栏颜色为半透明,这样半透明+白=灰, 状态栏的文字能看得清
             */
            StatusBarUtil.setStatusBarColor(this, 0x55000000)
        }
    }

    override fun onCreateView(
        name: String,
        context: Context,
        attrs: AttributeSet
    ): View? {
        /**
         * 为所有app界面添加灰度主题
         *
         */
//        if ("FrameLayout".equals(name)) {
//            int count = attrs.getAttributeCount();
//            for (int i = 0; i < count; i++) {
//                String attributeName = attrs.getAttributeName(i);
//                String attributeValue = attrs.getAttributeValue(i);
//                if (attributeName.equals("id")) {
//                    int id = Integer.parseInt(attributeValue.substring(1));
//                    String idVal = getResources().getResourceName(id);
//                    if ("android:id/content".equals(idVal)) {
//                        GrayFrameLayout grayFrameLayout = new GrayFrameLayout(context, attrs);
//                        return grayFrameLayout;
//                    }
//                }
//            }
//        }
        return super.onCreateView(name, context, attrs)
    }

    /**
     * open关键词表示可以被继承
     *
     */
    open fun initStatusBar() {}

    open fun initLiveEventBus() {}
    open fun initTitle() {}
    open fun initEventBusButterKnife() {}
    open fun initTablayout() {}
    open fun initSmart() {}
    open fun showLoadDialog() {}
    open fun showLoadDialog(title: String?) {}
    open fun hideLoadDialog() {}
}